package com.cognitran.cssvalidator.validation.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.w3c.css.css.StyleSheet;
import org.w3c.css.util.ApplContext;

/**
 * The container class for the results of a CSS validation.
 * 
 * @author garethf
 */
public class CSSValidationResults 
{

	/** The list of validation warnings (if any). */
	private final List<CSSWarning> warnings = new ArrayList<CSSWarning>();
	
	/** The list of validation errors (if any). */
	private final List<CSSError> errors = new ArrayList<CSSError>();
	
	
	/** The W3C context object used for validation. */
	private final ApplContext ctx;
	
	/** The W3C CSS validation / parsed CSS object. */
	private final StyleSheet css;
	
	/** The warning level threshold for filtering validation results. */
	private final int warningThresholdLevel;
	
	
	/**
	 * Create a new set of validation results.
	 * 
	 * @param ctx The W3C application context used for validation.
	 * @param css The W3C object resulting parsed CSS.
	 * @param warningThresholdLevel The level of warnings to filter at.
	 */
	public CSSValidationResults(final ApplContext ctx, final StyleSheet css, final int warningThresholdLevel)
	{
		this.ctx = ctx;
		this.css = css;
		this.warningThresholdLevel = warningThresholdLevel;
	}
	
	
	/**
	 * Add a warning to the validation results.
	 * 
	 * @param warning The CSS validation warning.
	 */
	public void addWarning(final CSSWarning warning)
	{
		warnings.add(warning);
	}
	
	
	/**
	 * Did the validation produce any warnings.
	 * 
	 * @return true If there were warnings, false otherwise.
	 */
	public boolean hasWarnings()
	{
		return warnings.size() > 0;
	}
	
	
	/**
	 * Get the list of warnings found.
	 * 
	 * @return An immutable list of CSS validation warnings.
	 */
	public List<CSSWarning> getWarnings()
	{
		return Collections.unmodifiableList(warnings);
	}
	
	
	/**
	 * Add a error to the validation results.
	 * 
	 * @param error The CSS validation error.
	 */
	public void addError(final CSSError error)
	{
		errors.add(error);
	}
	
	
	/**
	 * Did the validation produce any errors.
	 * 
	 * @return true If there were errors, false otherwise.
	 */
	public boolean hasErrors()
	{
		return errors.size() > 0;
	}
	
	
	/**
	 * Get the list of errors found.
	 * 
	 * @return An immutable list of CSS validation errors.
	 */
	public List<CSSError> getErrors()
	{
		return Collections.unmodifiableList(errors);
	}
	
	
	/**
	 * Get the W3C context used for validation.
	 * 
	 * @return The W3C <code>ApplContext</code> instance used.
	 */
	public ApplContext getContext()
	{
		return ctx;
	}
	
	
	/**
	 * Get the W3C parsed CSS.
	 * 
	 * @return The W3C <code>StyleSheet</code> instance generated.
	 */
	public StyleSheet getCss()
	{
		return css;
	}
	
	
	/**
	 * Get the warning level threshold for this validation.
	 * 
	 * @return The warning threshold level validation is held against.
	 */
	public int getWarningThresholdLevel()
	{
		return warningThresholdLevel;
	}
	
}
